//
//  HZGoodsDetailTotalCmtView.m
//  app
//
//  Created by 刘华舟 on 15/5/26.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZGoodsDetailTotalCmtView.h"

static const NSInteger kTotalCmtViewHeight = kHZGoodsDetailTotalCmtViewHeight;
static const NSInteger kTotalCmtLabelHeight = 40;
static const NSInteger kArrowImageWidth = 40;

@interface HZGoodsDetailTotalCmtView()

@property (strong, nonatomic) UIButton *arrowBtn;
@property (strong, nonatomic) UILabel *moreLabel;


@end


@implementation HZGoodsDetailTotalCmtView

- (void)drawRect:(CGRect)rect{
    [self drawBackground:self.bounds color:HZ_MALL_MAIN_THEME_WHITE];
    
    [self drawHorizonLineLeft:[self.ubo fw:0] right:[self.ubo fw:0] at:[self.ubo fh:UB_HEIGHT ph:-1] color:HZ_MALL_M_SEPARATOR_CELL_LINE];
    
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.backgroundColor = HZ_MALL_MAIN_THEME_WHITE;
        self.frame = CGRectOf([UBO_WINDOW fx:UB_LEFT fy:UB_TOP], [UBO_SCREEN fw:UB_WIDTH uh:kTotalCmtViewHeight]);
        self.contentMode = UIViewContentModeRedraw;
        //促销label
        self.tagLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.ubo fx:UB_LEFT ux:kSizeMallViewMargin fy:UB_TOP uy:kSizeMallViewMargin/2],
                                                                   [self.ubo fw:UB_WIDTH uw:-2*kSizeMallViewMargin-kArrowImageWidth uh:kTotalCmtLabelHeight])];
        
        
        self.tagLabel.textAlignment = NSTextAlignmentLeft;
        self.tagLabel.textColor = HZ_MALL_TEXT_GRAY_COLOR;
        self.tagLabel.font = kHZFont_Content_S;
        [self addSubview:self.tagLabel];
        
        //查看详情右箭头
        self.arrowBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.tagLabel.ufo fx:UB_RIGHT fy:UB_TOP],
                                                                  [self.tagLabel.ubo uw:kArrowImageWidth fh:UB_HEIGHT])];
        self.arrowBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [self.arrowBtn setImage:[UIImage imageNamed:kImageArrowRightBlue] forState:UIControlStateNormal];
        [self.arrowBtn addTarget:self action:@selector(arrowBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.arrowBtn];
        
        self.moreLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.tagLabel.ufo fx:UB_RIGHT ux:-kArrowImageWidth-kArrowImageWidth-kArrowImageWidth/2 fy:UB_TOP],
                                                                     [self.arrowBtn.ubo uw:3*kArrowImageWidth fh:UB_HEIGHT])];
        self.moreLabel.textAlignment = NSTextAlignmentRight;
        self.moreLabel.font = kHZFont_Content_S;
        self.moreLabel.textColor = HZ_MALL_MAIN_THEME_M_BLUE;
        self.moreLabel.text = @"查看更多";
        [self addSubview:self.moreLabel];
        
    }
    return self;
}

- (void)arrowBtnOnClick{
    if (self.seeAllTargetCaller) {
        [self.seeAllTargetCaller call];
    }
}


- (void)showPinglunNum:(NSString *)pinglunNum{
    if ([pinglunNum integerValue] <= 0) {
        self.tagLabel.text = @"暂无评论";
        self.arrowBtn.hidden = YES;
        self.moreLabel.hidden = YES;
    }else{
        self.tagLabel.text = [NSString stringWithFormat:@"宝贝评价(%@)", pinglunNum];
        self.arrowBtn.hidden = NO;
        self.moreLabel.hidden = NO;
    }
}

@end
